﻿Imports DTO
Imports System.Data.SqlClient
Public Class DICHVUDAO
    Private ketnoi As New DAO.connect()
    Public Function loaddichvu() As DataTable
        ketnoi.OpenConnection()
        Dim dtnv As New DataTable()
        Dim chuoi As String = "select * from DICHVU"
        dtnv = ketnoi.getDataTable(chuoi)
        ketnoi.CloseConnection()
        Return dtnv
    End Function
    Private Function Sqlcommand_THEM(ByVal MADICHVU As Integer, ByVal TENDICHVU As String, ByVal DONGIA As Double) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_THEM_DICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MADICHVU", SqlDbType.Int).Value = MADICHVU
        sqlcmd.Parameters.Add("@TENDICHVU", SqlDbType.NVarChar).Value = TENDICHVU
        sqlcmd.Parameters.Add("@DONGIA", SqlDbType.Float).Value = DONGIA



        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function them_DICHVU(ByVal dto As DICHVUDTO)
        ketnoi.OpenConnection()
        'Dim dto As New LOAISANHDTO()
        If Sqlcommand_THEM(dto.MADICHVU, dto.TENDICHVU, dto.DONGIA) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False
    End Function

    Private Function Sqlcommand_capnhat(ByVal MADICHVU As Integer, ByVal TENDICHVU As String, ByVal DONGIA As Double) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_CAPNHAT_DICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MADICHVU", SqlDbType.Int).Value = MADICHVU
        sqlcmd.Parameters.Add("@TENDICHVU", SqlDbType.Int).Value = TENDICHVU
        sqlcmd.Parameters.Add("@DONGIA", SqlDbType.Float).Value = DONGIA

        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function capnhat_dichvu(ByVal dto As DICHVUDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_capnhat(dto.MADICHVU, dto.TENDICHVU, dto.DONGIA) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

    Private Function Sqlcommand_XOA(ByVal MADICHVU As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_XOA_DICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        sqlcmd.Parameters.Add("@MADICHVU", SqlDbType.Int).Value = MADICHVU

        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function xoa_DICHVU(ByVal dto As DICHVUDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_XOA(dto.MADICHVU) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

End Class
